package org.lql.algo.codecrush.week009.question.type.II;

import org.lql.algo.common.Pair;
import org.lql.algo.common.TreeNode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author: liangqinglong
 * @date: 2025-08-20 16:53
 * @description: LCR 149. 彩灯装饰记录 I <a href="https://leetcode.cn/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/description/">...</a>
 **/
public class DecorateRecord {

	public int[] decorateRecord(TreeNode root) {
		List<Integer> res = new ArrayList<>();
		if (root == null) {
			return new int[0];
		}
		Queue<Pair<Integer, TreeNode>> queue = new LinkedList<>();
		queue.offer(new Pair<>(0, root));
		while (!queue.isEmpty()) {
			Pair<Integer, TreeNode> poll = queue.poll();
			int level = poll.getKey();
			TreeNode node = poll.getValue();
			res.add(node.val);
			if (node.left != null) {
				queue.offer(new Pair<>(level + 1, node.left));
			}
			if (node.right != null) {
				queue.offer(new Pair<>(level + 1, node.right));
			}
		}
		int[] ans = new int[res.size()];
		for (int i = 0; i < res.size(); i++) {
			ans[i] = res.get(i);
		}
		return ans;
	}

	public static void main(String[] args) {
		DecorateRecord decorateRecord = new DecorateRecord();
		TreeNode root = new TreeNode(8);
		root.right = new TreeNode(21);
		root.right.right = new TreeNode(6);
		root.left = new TreeNode(17);
		root.left.left = new TreeNode(18);
		System.out.println(Arrays.toString(decorateRecord.decorateRecord(root)));
	}
}
